package common;

import common.constant.HttpStatusEnum;

import java.io.Serializable;

public class MQR implements Serializable {
    private int code ;
    private String msg;
    private Object data;

    public MQR(){}

    public static MQR OK(){
        MQR r = new MQR();
        r.setCode(HttpStatusEnum.OK.getValue());
        r.setMsg(HttpStatusEnum.OK.getName());
        return r;
    }

    public static MQR OK(Object data){
        MQR r = new MQR();
        r.setCode(HttpStatusEnum.OK.getValue());
        r.setMsg(HttpStatusEnum.OK.getName());
        r.setData(data);
        return r;
    }

    public static MQR ERROR(){
        return ERROR(HttpStatusEnum.ERROR.getValue(), HttpStatusEnum.ERROR.getName());
    }

    public static MQR ERROR(String msg){
        return ERROR(HttpStatusEnum.ERROR.getValue(),msg);
    }

    public static MQR ERROR(int code, String msg){
        MQR r = new MQR();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString(){
        return "R(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }

}
